using Godot;
using System;

public partial class Interactable : Area2D
{
	[Export]
	public string tips;//提示文字
	private Player _player;
	private Map _map;
	public override void _Ready()
	{
		CollisionLayer = 0;
		CollisionMask = 0;
		SetCollisionMaskValue(2,true);
		BodyEntered += OnInteractableBodyEntered;
		BodyExited += OnInteractableBodyExited;
		//GD.Print("jiedianming",GetTree().CurrentScene.GetChild(0).Name);

		var Game = GetNode<Game>("/root/Game");
		_player = Game.get_player();
		//GD.Print("wanjia",_player.Name);
	}
	public virtual void Interact()
	{
		//GD.Print("存档");
		//_player._saveLoadManager.Save();
		Map map = Owner as Map;
		//GD.Print(map.Name , map.Position);
	}
	public virtual void OnInteractableBodyEntered(Node2D player)//信号，进入区域
	{
		var Game = GetNode<Game>("/root/Game");
		_player = Game.get_player();
		//GD.Print("进入区域");
		if(this.tips == "")
		{return;}
		if(player is Player)
		{
			var UIControl = GetNode<UIControl>("/root/UIControl");
			UIControl.GetGuiViewManager().open_view("UiInteractTips");
			_player.register_interactable(this);
			(_player.CharacterData as PlayerData).InteractTips = this.tips;
		}
		//GD.Print("进入区域",(_player.CharacterData as PlayerData).InteractTips);
	}
	public virtual void OnInteractableBodyExited(Node2D player)
	{
		var Game = GetNode<Game>("/root/Game");
		_player = Game.get_player();
		if(player is Player)
		{
			var UIControl = GetNode<UIControl>("/root/UIControl");
			UIControl.GetGuiViewManager().close_view("UiInteractTips");
			_player.unregister_interactable(this);
			(_player.CharacterData as PlayerData).InteractTips = "";
		}
		//GD.Print("退出区域",(_player.CharacterData as PlayerData).InteractTips);
	}
}
